Imports System.Data
Imports System.Data.SqlClient
Imports System.Net.Mail
Imports System.Collections.Generic
Imports SubSonic
Imports ClubStarterKit.Data

Partial Class Blogs_Post
    Inherits System.Web.UI.Page
    Public IsAdmin As Boolean
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Request("id") Is Nothing Then
            Response.Redirect("Default.aspx")
        End If
        If Page.User.Identity.IsAuthenticated = True Then
            addcommentdiv.Visible = True

        Else
            addcommentdiv.Visible = False
        End If
        IsAdmin = User.IsInRole("Blogger")

    End Sub


    Protected Sub ImageButton1_Click(ByVal sender As Object, ByVal e As System.Web.UI.ImageClickEventArgs) Handles ImageButton1.Click
        Response.Redirect("~/rss/CommentsRss.aspx?blogid=" & CStr(Request("id")))
    End Sub

    Protected Sub HyperLink2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim qry As New Query(Tables.BlogPosts)
        qry.AddWhere(BlogPosts.Columns.Postid, Request("id"))
        qry.QueryType = QueryType.Delete

        Dim commqry As New Query(Tables.BlogComments)
        commqry.QueryType = QueryType.Delete
        commqry.AddWhere(BlogComments.Columns.Postid, Request("id"))

        Dim sql As String = qry.GetSql()
        sql += "\r\n"
        sql += commqry.GetSql()

        Dim cmd As New SubSonic.QueryCommand(sql)
        SubSonic.DataService.ExecuteQuery(cmd)

        Response.Redirect("~/blogs/default.aspx")
    End Sub

    Protected Sub AddComment_Click(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsValid = True Then
            Dim TheQueryString As Int32 = CInt(Request("id"))
            Dim mem As MembershipUser = Membership.GetUser()
            Dim gui As New Guid(mem.ProviderUserKey.ToString)
            Dim name As String = ClubStarterKit.Web.Members.FirstAndLastName(gui)
            Dim email As String = mem.Email.ToString()
            BlogComments.Insert(TheQueryString, name, email, txtComment.Text)
            txtComment.Text = ""
            UpdatePanel1.Update()
        End If
    End Sub
End Class
